package com.jhf.skypac_pda.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.jhf.skypac_pda.R;
import com.jhf.skypac_pda.adapter.interfaces.BaseAdapter;
import com.jhf.skypac_pda.model.MaterialtankfeedingorderModel;

import java.util.List;

public class MaterialtankfeedingorderListAdapter extends BaseAdapter<MaterialtankfeedingorderListAdapter.MaterialtankfeedingorderListItemHolder> {
    private List<MaterialtankfeedingorderModel> mList;
    private Context context;



    public MaterialtankfeedingorderListAdapter(Context mContext, @NonNull List<MaterialtankfeedingorderModel> mList) {
        this.mList = mList;
        this.context = mContext;
    }

    @Override
    public MaterialtankfeedingorderListAdapter.MaterialtankfeedingorderListItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.exporder_list_item, parent, false);
        MaterialtankfeedingorderListAdapter.MaterialtankfeedingorderListItemHolder holder = new MaterialtankfeedingorderListAdapter.MaterialtankfeedingorderListItemHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MaterialtankfeedingorderListAdapter.MaterialtankfeedingorderListItemHolder holder, final int position) {
        holder.order_id.setText(mList.get(position).getMaterialTankFeedingOrderCode());


        holder.order_tank.setText("料罐" + mList.get(position).getMaterialTankNum());

        String status = mList.get(position).getMaterialTankFeedingOrderStatusDesc();
        holder.order_status.setText(status);
        if (status.equals("待投料")) {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.title_text_num));
        } else if (status.equals("投料完成")) {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.status_feeding_done));
        } else if (status.equals("投料中")) {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.status_feeding));
        } else {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.title_text_quit));
        }

        holder.invest_num.setText((int)Float.parseFloat(mList.get(position).getMaterialTankFeedingBagCount()) + "");


        holder.need_origin.setText(mList.get(position).getMaterialTankFeedingOrderSourceDesc());

        holder.ll_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=mViewClickListener){
                    mViewClickListener.post_detail(position);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class MaterialtankfeedingorderListItemHolder extends RecyclerView.ViewHolder {
        TextView order_id;
        TextView order_tank;
        TextView order_status;
        TextView need_origin;
        TextView invest_num;
        LinearLayout ll_order;

        public MaterialtankfeedingorderListItemHolder(View itemView) {
            super(itemView);
            order_id=itemView.findViewById(R.id.order_id);
            order_tank=itemView.findViewById(R.id.order_tank);
            order_status=itemView.findViewById(R.id.order_status);
            need_origin=itemView.findViewById(R.id.tv_laiyuan);
            invest_num=itemView.findViewById(R.id.invest_num);
            ll_order=itemView.findViewById(R.id.ll_order);
        }
    }

    public interface ViewClickListener{
        void post_detail(int pos);
    }

    public void setViewClickListener(MaterialtankfeedingorderListAdapter.ViewClickListener mViewClickListener){
        this.mViewClickListener=mViewClickListener;

    }


    private MaterialtankfeedingorderListAdapter.ViewClickListener mViewClickListener;

}
